package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import javafx.scene.shape.CubicCurve;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.MyCyhVipPartnerMapper;
import com.laowang.project.system.domain.MyCyhVipPartner;
import com.laowang.project.system.service.MyCyhVipPartnerService;
import oshi.jna.platform.mac.SystemB;

/**
 * 会员合作人配置Service业务层处理
 *
 * @author laowang
 * @date 2024-01-08
 */
@Service
public class MyCyhVipPartnerServiceImpl implements MyCyhVipPartnerService {
    @Autowired
    private MyCyhVipPartnerMapper myCyhVipPartnerMapper;

    /**
     * 查询会员合作人配置
     *
     * @param id 会员合作人配置ID
     * @return 会员合作人配置
     */
    @Override
    public MyCyhVipPartner selectMyCyhVipPartnerById(Integer id) {
        return myCyhVipPartnerMapper.selectMyCyhVipPartnerById(id);
    }

    /**
     * 查询会员合作人配置列表
     *
     * @param myCyhVipPartner 会员合作人配置
     * @return 会员合作人配置
     */
    @Override
    public List<MyCyhVipPartner> selectMyCyhVipPartnerList(MyCyhVipPartner myCyhVipPartner) {
        return myCyhVipPartnerMapper.selectMyCyhVipPartnerList(myCyhVipPartner);
    }

    /**
     * 新增会员合作人配置
     *
     * @param myCyhVipPartner 会员合作人配置
     * @return 结果
     */
    @Override
    public int insertMyCyhVipPartner(MyCyhVipPartner myCyhVipPartner) {
        Integer vipLevel = myCyhVipPartner.getVipLevel();
        Integer partnerId = myCyhVipPartner.getPartnerId();
        if (vipLevel == null){
            throw new CustomException("会员不能为空");
        }
        if (partnerId == null){
            throw new CustomException("合伙人不能为空");
        }
        MyCyhVipPartner myCyhVipPartner1 =  myCyhVipPartnerMapper.selectOneByVipAndpaId(vipLevel,partnerId);
        if (myCyhVipPartner1 != null){
            throw new CustomException("该会员与合伙人的配置已存在");
        }
        return myCyhVipPartnerMapper.insertMyCyhVipPartner(myCyhVipPartner);
    }

    /**
     * 修改会员合作人配置
     *
     * @param myCyhVipPartner 会员合作人配置
     * @return 结果
     */
    @Override
    public int updateMyCyhVipPartner(MyCyhVipPartner myCyhVipPartner) {
        Integer vipLevel = myCyhVipPartner.getVipLevel();
        Integer partnerId = myCyhVipPartner.getPartnerId();
        if (vipLevel == null){
            throw new CustomException("会员不能为空");
        }
        if (partnerId == null){
            throw new CustomException("合伙人不能为空");
        }
        MyCyhVipPartner myCyhVipPartner1 =  myCyhVipPartnerMapper.selectOneByVipAndpaId(vipLevel,partnerId);
        if (myCyhVipPartner1 != null){
            if (!myCyhVipPartner1.getId().equals(myCyhVipPartner.getId())){
                throw new CustomException("该会员与合伙人的配置已存在");
            }
        }

        return myCyhVipPartnerMapper.updateMyCyhVipPartner(myCyhVipPartner);
    }

    /**
     * 批量删除会员合作人配置
     *
     * @param ids 需要删除的会员合作人配置ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhVipPartnerByIds(Integer[] ids) {
        return myCyhVipPartnerMapper.deleteMyCyhVipPartnerByIds(ids);
    }

    /**
     * 删除会员合作人配置信息
     *
     * @param id 会员合作人配置ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhVipPartnerById(Integer id) {
        return myCyhVipPartnerMapper.deleteMyCyhVipPartnerById(id);
    }
}
